import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '编码',
    align: "center",
    sorter: true,
    dataIndex: 'code'
  },
  {
    title: '名称',
    align: "center",
    sorter: true,
    dataIndex: 'name'
  },
  {
    title: '计划年份',
    align: "center",
    sorter: true,
    dataIndex: 'planYear',
    width: 100
  },
  {
    title: '期间规则',
    align: "center",
    dataIndex: 'periodRule',
    width: 100,
    customRender: ({ text }) => {
      return text == 0 ? '月份' : text == 1 ? '季度' : text == 2 ? '自定义' : ''
    },
  },
  {
    title: '期间数',
    align: "center",
    sorter: true,
    dataIndex: 'periodNumber',
    width: 90
  },
  {
    title: '是否启用',
    align: "center",
    dataIndex: 'enabledStatus',
    width: 100,
    customRender: ({ text }) => {
      return text == 1 ? '是' : '否'
    },
  },
  {
    title: '备注',
    align: "center",
    dataIndex: 'remark'
  },
  {
    title: '第三方编码',
    align: "center",
    dataIndex: 'thirdPartyCode',
    ifShow: false
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "编码",
    field: "code",
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: "计划年份",
    field: "planYear",
    component: 'DatePicker',
    colProps: { span: 2 },
    componentProps: {
      picker: 'year',
      showTime: false,
      readonly: true
    },
  },
  {
    label: "名称",
    field: "name",
    component: 'Input',
    colProps: { span: 6 },
  },

  {
    label: "期间数",
    field: "periodNumber",
    component: 'Input',
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '编码',
    field: 'code',
    component: 'Input',
  },
  {
    label: '名称',
    field: 'name',
    component: 'Input',
    dynamicRules: () => [{ required: true, message: '请输入计划周期名称!' }]
  },
  {
    label: "计划年份",
    field: 'planYear',
    component: 'DatePicker',
    componentProps: {
      picker: 'year',
      showTime: false,
      readonly: true
      // valueFormat: 'YYYY'
    },
  },
  {
    label: '期间规则',
    field: 'periodRule',
    component: 'Select',
    defaultValue: 0,
    componentProps: {
      options: [{ label: '月份', value: 0 }, { label: '季度', value: 1 }, { label: '自定义', value: 2 }],
      stringToNumber: true,
    }
  },
  {
    label: '期间数',
    field: 'periodNumber',
    component: 'InputNumber',
    componentProps: {
      min: 0
    },
  },
  {
    label: '是否启用',
    field: 'enabledStatus',
    defaultValue: 1,
    component: 'Select',
    componentProps: {
      options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
      stringToNumber: true,
    }
  },

  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
    ifShow: false
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
//子表单数据
//子表表格配置
export const basPlanCycleItemColumns: JVxeColumn[] = [
  {
    title: '计划周期ID',
    key: 'planCycleId',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '计划年份',
    key: 'planYear',
    type: JVxeTypes.slot,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
    slotName: "yearSlot"
  },
  {
    title: '期间号',
    key: 'periodNo',
    type: JVxeTypes.inputNumber,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '期间规则',
    key: 'periodRule',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 0,
    options: [{ label: '月份', value: 0 }, { label: '季度', value: 1 }, { label: '自定义', value: 2 }],
  },
  {
    title: 'MPS排产是否启用',
    key: 'mpsProductSchedule',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
  },
  {
    title: '总装排产是否启用',
    key: 'assemblyProductSchedule',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
  },
  {
    title: '前工序排产是否启用',
    key: 'preProcessProductSchedule',
    type: JVxeTypes.select,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: 1,
    options: [{ value: 1, label: '是' }, { value: 0, label: '否' }],
  },
  {
    title: '备注',
    key: 'remark',
    type: JVxeTypes.input,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '第三方编码',
    key: 'thirdPartyCode',
    type: JVxeTypes.hidden,
    width: "200px",
    placeholder: '请输入${title}',
    defaultValue: '',
  },
]


/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}